package com.monkey.demo.controller;

import com.monkey.bean.Result;
import com.monkey.demo.entity.SysUser;
import com.monkey.demo.entity.dto.UserDto;
import com.monkey.demo.entity.req.UserReq;
import com.monkey.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(value = "测试UserController",tags = "测试用户接口UserController",description = "测试用户接口")
@Slf4j
public class UserController {


    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/addOrUpdateUser")
    public Result addOrUpdateUser(@RequestBody UserReq userReq){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq,userDto);
        int i = userService.addOrUpdateUser(userDto);
        return Result.ok(i);
    }

    @DeleteMapping("/{userId}")
    public Result delUserById(@PathVariable Long userId){
        return userService.delUserById(userId);
    }

    @GetMapping("/testRedis")
    @ApiOperation(value = "测试reis",notes = "测试reis")
    public void testRedis(){
        redisTemplate.opsForValue().set("name","123456");
    }

    @GetMapping("/testAsynchronousLog")
    @ApiOperation(value = "测试reis",notes = "测试reis")
    public void testAsynchronousLog(){
        long beginTime=System.currentTimeMillis();
        for (int i = 1; i <= 100000; i++) {
            log.info("这是第{}条日志信息数据",i);
        }
        long totalTime=System.currentTimeMillis()-beginTime;
        log.info("总计耗时:{}",totalTime);
    }

    @PostMapping("/testTranslateDate")
    @ApiOperation(value = "全局时间处理测试",notes = "全局时间处理测试")
    public void testTranslateDate(@RequestBody SysUser sysUser){
        System.out.println("全局时间处理测试!!");
        System.out.println(sysUser);
    }


}
